<template>
    <view class="content" v-if="isShow">
        <view class="nav">
            <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">待装车({{count.count2}})</view>
            <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">运输中({{count.count3}})</view>
            <view class="nav-i" :class="{active : type == 4}" @click="chooseNav(4)">已到达</view>
        </view>
        
		<template v-if="type == 2">
			<view class="nav2">
			    <view class="u-flex">
			        <view class="nav2-i" :class="{active2 : tab == 1}" @click="chooseTab(1)">零担</view>
			        <view class="nav2-i" :class="{active2 : tab == 2}" @click="chooseTab(2)">包车</view>
			    </view>
			    <view class="nav2-r">
			        <view>日期检索</view>
			        <view class="time" @click="show = true">
			            <view>{{date || '请选择'}}</view>
			            <image src="../../static/icon/time.png" class="time-icon"></image>
			        </view>
			    </view>
			</view>
			
			<view class="u-p-l-20 u-p-r-20">
			    <u-search placeholder="输入收货方名称" v-model="keyword" :show-action="false" bg-color="#fff" @search="doSearch"></u-search>
			</view>
		</template>
        
        <view class="box" v-if="type == 2" v-for="(item, index) in list" :key="index" @click="toDetails(item)">
            <view class="top">
                <view class="item u-flex-1">
                    <view class="left">订单编号</view>
                    <view class="right">{{item.out_trade_no}}</view>
                </view>
				<!-- create_type 1用户 4发货端 5卸货端 -->
                <view class="u-flex">
                    <view class="o-sta3" v-if="item.create_type == 1">用户创建</view>
					<view class="o-sta4" v-if="item.create_type == 4">发货创建</view>
					<view class="o-sta4" v-if="item.create_type == 5">卸货创建</view>
                    <!-- <view class="o-sta4" v-else>现场创建</view> -->
                </view>
            </view>
            <view class="item">
                <view class="left">下单日期</view>
                <view class="right">{{item.create_time}}</view>
            </view>
            <view class="item">
                <view class="left">发货方</view>
                <view class="right">{{item.shipper}}</view>
            </view>
            <view class="item">
                <view class="left">联系人</view>
                <view class="right">{{item.shipper_contact}}</view>
            </view>
            <view class="item">
                <view class="left">联系方式</view>
                <view class="right">{{item.shipper_phone}}</view>
            </view>
            <view class="item">
                <view class="left">装车地点</view>
                <view class="right">{{item.loading_site}}</view>
            </view>
            <view class="item">
                <view class="left">收货地址</view>
                <view class="right">{{item.address}}</view>
            </view>
            
            <view class="item">
                <view class="left">经营位置</view>
                <view class="right">{{item.position}}</view>
            </view>
            <view class="item">
                <view class="left">联系人</view>
                <view class="right">{{item.recipient_contact}}</view>
            </view>
            <view class="item">
                <view class="left">联系方式</view>
                <view class="right">{{item.recipient_phone}}</view>
            </view>
            <view class="item">
                <view class="left">发车时间</view>
                <view class="right">{{item.start_time}}</view>
            </view>
            <view class="item" v-if="item.carriage">
                <view class="left">车厢位置</view>
                <view class="right">{{item.carriage}}</view>
            </view>
        </view>
        
        <view class="box" v-if="type != 2" v-for="(item, index) in list" :key="index" @click="toDetails(item)">
            <view class="top">
                <view class="item u-flex-1">
                    <view class="left">运单编号</view>
                    <view class="right">{{item.out_trade_no}}</view>
                </view>
                <view class="u-flex">
                    <!-- <view class="o-sta3" v-if="item.create_type == 1">用户创建</view>
                    <view class="o-sta4" v-else>现场创建</view> -->
                    <view class="o-sta1" v-if="item.order_type == 1">零担</view>
                    <view class="o-sta2" v-if="item.order_type == 2">包车</view>
                </view>
            </view>
            <view class="item">
                <view class="left">运输线路</view>
                <view class="right">{{item.line}}</view>
            </view>
            <view class="item">
                <view class="left">司机</view>
                <view class="right">{{item.name}}</view>
            </view>
            <view class="item">
                <view class="left">车牌号</view>
                <view class="right">{{item.number}}</view>
            </view>
            <view class="item">
                <view class="left">联系方式</view>
                <view class="right">{{item.phone}}</view>
            </view>
            <view class="item">
                <view class="left">装车时间</view>
                <view class="right">2023-11-22 16:00</view>
            </view>
            <view class="item">
                <view class="left">装车开始时间</view>
                <view class="right">{{item.load_start_time}}</view>
            </view>
            
            <view class="item">
                <view class="left">装车结束时间</view>
                <view class="right">{{item.load_end_time}}</view>
            </view>
            <view class="item" v-if="item.expect_time">
                <view class="left">预计到达时间</view>
                <view class="right">{{item.expect_time}}</view>
            </view>
            <view class="item" v-if="item.arrival_time">
                <view class="left">司机到达时间</view>
                <view class="right">{{item.arrival_time}}</view>
            </view>
            <view class="item">
                <view class="left">总件数</view>
                <view class="right">{{item.all_num}}件</view>
            </view>
            <view class="item">
                <view class="left">总重量</view>
                <view class="right">{{item.all_weight}}斤</view>
            </view>
            <view class="item" v-if="item.ask">
                <view class="left">卸车要求</view>
                <view class="right">{{item.ask}}</view>
            </view>
            <view class="item" v-if="item.route">
                <view class="left">运输路线</view>
                <view class="right">{{item.route}}</view>
            </view>
            <view class="item" v-if="item.kilometer_img">
                <view class="left">货物摆放图</view>
                <view class="right">
                    <image :src="item.kilometer_img" class="img" @click.stop="$previewImageSA(item.kilometer_img)"></image>
                </view>
            </view>
            <view class="item" v-if="item.seal_img">
                <view class="left">签封照片</view>
                <view class="right">
                    <image :src="item.seal_img" class="img" @click.stop="$previewImageSA(item.seal_img)"></image>
                </view>
            </view>
        </view>
    
		<view style="height: 94rpx;padding-top: 30rpx;">
		    <u-loadmore :status="status" v-if="status != 'loadmore'" />
		</view>
		
		<!-- 日期检索 -->
		<u-picker mode="time" v-model="show" @confirm="confirm"></u-picker>
	</view>
</template>

<script>
    export default {
        data() {
            return {
				show: false,
                type: 2,
                tab: 1,//1零担 2包车
                date: '',
				keyword: '',
				status: 'loadmore', //是否显示没有更多了
				page: 1,
				list: [],
				count: {},
				isShow: false,
            };
        },
        onLoad() {
            this.getList()
			// uni.startPullDownRefresh();
        },
		onPullDownRefresh() {
			let _this = this
			console.log('refresh');
			setTimeout(() => {
				_this.list = [];
				_this.page = 1;
				_this.status = 'loadmore';
				_this.getList();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			if(this.page == 1){return}
			this.getList()
		},
        methods: {
            toDetails(item) {
				if (this.type == 2) {
					this.$gTo(`/pages/send-records/ld-details?id=${item.id}`)
				} else {
					this.$gTo(`/pages/send-records/ld-list?id=${item.id}&type=${this.type}`)
					// if (item.order_type == 1) {
					//     this.$gTo(`/pages/send-records/ld-list?id=${item.id}&type=${this.type}`)
					// } else {
					//     this.$gTo(`/pages/send-records/ld-details?id=${item.id}`)
					// }
				}
            },
			
			doSearch() {
				this.list = []
				this.page = 1
				this.status = 'loadmore'
				this.getList()
			},
			
			confirm(e) {
				console.log(e)
				this.date = e.year + '-' + e.month + '-' + e.day
				this.doSearch()
			},
            
            chooseNav(num) {
				if (this.type == num) return
				this.date = ''
				this.keyword = ''
				this.type = num
				this.doSearch()
            },
            
            chooseTab(num) {
				if (this.tab == num) return
				this.tab = num
				this.doSearch()
            },
			
			getList() {
				if (this.status == 'nomore') return;
				this.status = 'loading';
				this.$ajax('shipping_records', {
					user_token: this.$getSync('userToken'),
					page: this.page,
					limit: 10,
			        status: this.type,//2待装车 3运输中 4已到达
					order_type: this.type == 2 ? this.tab : '',//1零担 2包车
					date: this.date,//日期
					name: this.keyword,
				}).then(ret => {
					if (ret.success == 1000) {
						this.count = ret.detail
						
						if (ret.detail && ret.detail.data && ret.detail.data.length > 0) {
							this.list = this.list.concat(ret.detail.data);
							this.page++;
							this.status = 'loadmore'
						} else {
							this.status = 'nomore'
						}
						this.isShow = true
					} else {
						this.$toast(ret.msg);
					}
				});
			},
        }
    };
</script>

<style lang="scss">
    .img{
        width: 245rpx;
        height: 170rpx;
    }
    
    
    page{
        background-color: #eef1f6;
    }
    .content{
        padding-bottom: 50rpx;
    }
    .nav{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx 0;
        border-bottom: 2rpx solid #ebebeb;
        background-color: #fff;
    }
    .nav-i{
        width: calc(100vw / 3);
        font-size: 28rpx;
        text-align: center;
        position: relative;
    }
    .active{
        color: #004580;
        font-weight: bold;
        position: relative;
    }
    .active::after{
        display: block;
        content: '';
        width: 32rpx;
        height: 8rpx;
        background-color: #004580;
        position: absolute;
        bottom: -30rpx;
        left: 50%;
        transform: translateX(-50%);
    }
    
    .nav2{
        padding: 20rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .nav2-i{
        padding: 15rpx 45rpx;
        margin-right: 15rpx;
        background-color: #fff;
        border-radius: 15rpx;
        font-size: 28rpx;
    }
    .active2{
        background-color: #004580;
        color: #fff;
    }
    .nav2-r{
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 24rpx;
        color: #737373;
    }
    .time{
        min-width: 210rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #000;
        margin-left: 12rpx;
        padding: 15rpx;
        background-color: #fff;
        border-radius: 10rpx;
    }
    .time-icon{
        width: 25rpx;
        height: 25rpx;
        margin-left: 20rpx;
    }
    
    .box{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 40rpx 30rpx 30rpx;
        margin: 16rpx 20rpx 0;
    }
    .top{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 10rpx;
    }
    .left{
        width: 190rpx;
        color: #656565;
    }
    .right{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
    }
    .o-sta{
        font-size: 24rpx;
        color: #ff602c;
        padding-bottom: 10rpx;
        padding-left: 10rpx;
    }
    .o-sta1{
        font-size: 24rpx;
        color: #ff602c;
        padding: 7rpx 15rpx;
        background-color: #fff1ec;
        border-radius: 10rpx;
        margin-left: 10rpx;
        margin-bottom: 10rpx;
    }
    .o-sta2{
        font-size: 24rpx;
        color: #0075ff;
        padding: 7rpx 15rpx;
        background-color: #ebf4fe;
        border-radius: 10rpx;
        margin-left: 10rpx;
        margin-bottom: 10rpx;
    }
    .o-sta3{
        font-size: 24rpx;
        color: #ff602c;
        padding: 7rpx 15rpx;
        border: 2rpx solid #ff602c;
        border-radius: 10rpx;
        margin-left: 10rpx;
        margin-bottom: 10rpx;
        box-sizing: border-box;
    }
    .o-sta4{
        font-size: 24rpx;
        color: #0075ff;
        padding: 7rpx 15rpx;
        border: 2rpx solid #0075ff;
        border-radius: 10rpx;
        margin-left: 10rpx;
        margin-bottom: 10rpx;
        box-sizing: border-box;
    }
    
    

</style>
